package view.quest
{
import flash.display.DisplayObject;
import flash.display.MovieClip;

import framework.core.FontLib;
import framework.core.popup.PopUpManager;
import framework.proxy.ComponentProxy;
import framework.utils.TextUtil;
import framework.view.components.button.ButtonProxy;

import values.quest.QuestValue;

import view.component.bonus.BonusGroupProxy;
import view.component.button.OKButtonProxy;

/**
 * QuestDetailUIProxy
 * @author jliang
 * 
 */
public class QuestDetailUIProxy extends QuestComponentProxyBase
{
	//==========================================================================
	//  Constructor
	//==========================================================================
	public function QuestDetailUIProxy()
	{
		super();
	}
	//==========================================================================
	//  Variables
	//==========================================================================
	protected var goalProxys:Vector.<QuestDetailGoalRenderProxy> = new Vector.<QuestDetailGoalRenderProxy>();
	protected var okBtn:ButtonProxy;
	protected var bonus:BonusGroupProxy;
	//==========================================================================
	//  Overridden methods: ComponentProxy
	//==========================================================================
	override public function parse(target:MovieClip):void
	{
		super.parse(target);
		
		bonus = new BonusGroupProxy();
		bonus.parse(skin.bonusGroup);
		
		for (var i:int = 0; i < skin.numChildren; i++)
		{
			var child:DisplayObject = skin.getChildAt(i);
			if (child.name.indexOf("goal_render_") >= 0)
			{
				var goalProxy:QuestDetailGoalRenderProxy = new QuestDetailGoalRenderProxy();
				goalProxy.parse(child as MovieClip);
				goalProxys.push(goalProxy);
			}
		}
		
		okBtn = new OKButtonProxy();
		okBtn.parse(skin.okBtn);
		okBtn.onClick = clickToClose;
	}
	
	override public function dispose():void
	{
		if (okBtn)
		{
			okBtn.dispose();
			okBtn = null;
		}
		if (bonus)
		{
			bonus.dispose();
			bonus = null;
		}
		super.dispose();
	}
	
	override public function set data(value:QuestValue):void
	{
		super.data = value;
		
		TextUtil.setText(skin.nameLabel, data.template.name);
		TextUtil.setText(skin.descLabel, data.template.desc, FontLib.DESC_FONT_NAME);
		
		bonus.data = data.template.bonus;
		
		for each (var goalProxy:QuestDetailGoalRenderProxy in goalProxys)
		{
			goalProxy.data = data;
		}
	}
	
	protected function clickToClose():void
	{
		PopUpManager.close(skin.parent);
		uiComplete();
	}
}
}




